<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优惠券管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" charset="utf-8" src="//g.alicdn.com/sd/ncpc/nc.js?t=2015052012"></script>
    <script src="layui/layui.js"></script>
</head>
<body>

<div style="margin-bottom: 5px;">

    <!-- 示例-970 -->
<!--    <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>-->

</div>
<div class="layui-container">
<div class="layui-btn-container">
    <button class="layui-btn" test-active="test-form1">新建优惠券</button>
    <button class="layui-btn" test-active="test-form2">导出全部</button>
</div>
</div>
<table class="layui-table" lay-data="{width: 792, height:330, url:'/cp', page:true, id:'idTest'}" lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field:'id', width:80,align:'center', sort: true, fixed: true}">ID</th>
        <th lay-data="{field:'name', width:160,align:'center',}">名称</th>
        <th lay-data="{field:'colletExpire', width:160,align:'center', sort: true}">领用有效期</th>
        <th lay-data="{field:'useExpire', width:160,align:'center',sort: true}">使用有效期</th>
        <th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">下架</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">上架</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">详情</a>
</script>



<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    var $=layui.jquery;
    layui.use('table', function(){
        var table = layui.table;
        var $=layui.jquery;
        var layer = layui.layer
            ,form = layui.form
            ,laypage = layui.laypage
            ,element = layui.element
            ,laydate = layui.laydate
            ,util = layui.util;

        //新建优惠券

        util.event('test-active', {
            'test-form1': function(){
                layer.open({
                    type: 2
                    ,title:'新建优惠券'
                    ,resize: false
                    ,shadeClose: true
                    ,area: ['520px','520px']
                    ,content:'cpnAdd.html'
                    ,success: function(layero){
                        // layero.find('.layui-layer-content').css('overflow', 'visible');
                        //
                        // form.render().on('submit(*)', function(data){
                        //     layer.msg(JSON.stringify(data.field));
                        // });
                        //这里写json数据的传值,把父类传给子界面
                    }
                });
            }
        });


        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            }
            // 详情
            else if(obj.event === 'del'){
                layer.open({
                    type: 2
                    ,resize: false
                    ,title:'详情'
                    ,shadeClose: true
                    ,area: ['520px','520px']
                    ,content:'cpnDetail.html'
                    ,success: function(res){
                        // layero.find('.layui-layer-content').css('overflow', 'visible');
                        //
                        // form.render().on('submit(*)', function(data){
                        //     layer.msg(JSON.stringify(data.field));
                        // });


                        // var jsonStr = JSON.stringify(res);
                        // window.location.href="cpnDetail.html?orderData=" + jsonStr;



                    }
                });
            }
            else if(obj.event === 'edit'){
                layer.alert('编辑行：<br>'+ JSON.stringify(data))
            }
        });

        //新建优惠券

        //导出


    });
</script>

</body>




</html>